﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using V5_EShop._Class.BLL.GZ;

namespace V5_EShop
{
    public partial class Login : BasicPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string username = Request.Form["username"] + "";
            string pwd = Request.Form["password"] + "";
            string validCode = Request.Form["validCode"] + string.Empty;

            string vCode = Session["ValidateCode"] + string.Empty;

            if (validCode != "" && vCode.Trim().ToLower().Equals(validCode.Trim().ToLower()))
            {
                username = username.Replace("'", "").Replace("=", "");
                pwd = pwd.Replace("'", "").Replace("=", "");

                int i = new BLLGZUser().CheckUser(username, pwd);

                if (i != 1)
                {
                    WriteMsg("alert('用户名或密码错误！');window.location.href='/index.aspx?t=login'");
                }

                var user = new BLLGZUser().GetModel( (System.Guid)new BLLGZUser().GetList(" CustomName ='" + username + "' and pwd='" + pwd + "' ").Tables[0].Rows[0]["ID"]); 
                Session["isLogin"] = user;


                Response.Redirect("/index.aspx?t=user/MyBill");

            }
            else
            {
                WriteMsg("alert('你输入的验证码有误！请重新输入');window.location.href='/index.aspx?t=login'");
            }



        }


        private void WriteMsg(string info)
        {
            Response.Write("<script>" + info + "</script>");
            Response.End();
        }


    }
}